package org.hbnu.bookmanage001.service;
import org.hbnu.bookmanage001.entity.Book;
import org.hbnu.bookmanage001.mapper.BookMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//图书服务类
@Service
public class BookService implements BookMapper {

    @Autowired
    BookMapper bookMapper;

    @Override
    public List<Book> getAllBooks() {
        return bookMapper.getAllBooks();
    }

    @Override
    public int getNums() {
        return bookMapper.getNums();
    }

    @Override
    public List<Book> getBooksByPage(int start, int limit) {
        return bookMapper.getBooksByPage(start, limit);
    }

    @Override
    public Book getBookById(int id) {
        return bookMapper.getBookById(id);
    }

    @Override
    public List<Book> getBooksByName(String name) {
        return bookMapper.getBooksByName(name);
    }

    @Override
    public void addBook(Book book) {
        if (book.name.trim().isEmpty()) {
            System.out.println("图书名字不能为空！");
            return;
        }
        bookMapper.addBook(book);
    }

    @Override
    public void deleteBook(int id) {
        if (bookMapper.getBookById(id) == null) {
            System.out.println("删除的图书不存在");
            return;
        }
        bookMapper.deleteBook(id);
    }

    @Override
    public void updateBook(Book book) {
        bookMapper.updateBook(book);
    }
}
